def myStrip(str):
    begin=0
    end=len(str)
    for i,ch in enumerate(str):
        if(ch!=" "):
            begin=i
            break

    for i,ch in enumerate(reversed(str)):
        if(ch!=" "):
            end=end-i
            break
    return str[begin:end]

print myStrip("   abcd   deff m     ")



